package com.grao.waterschool.human.controller;

import lombok.extern.slf4j.Slf4j;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * @author limk
 * @date 2024/4/9 13:14
 */
@Slf4j
public class ShellScriptExecutor implements Runnable {

    private final String scriptPath;

    public ShellScriptExecutor(String scriptPath) {
        this.scriptPath = scriptPath;
    }

    @Override
    public void run() {
        try {
            Process process = Runtime.getRuntime().exec(scriptPath);
            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line;
            while ((line = reader.readLine()) != null) {
                log.info(line);
            }
            process.waitFor();
        } catch (Exception ignored) {
        }
    }
}
